import Vue from "vue";
import VueRouter from "vue-router";
import Login from "../views/login/index.vue";
import Detail from "../views/Detail.vue";
//import Login from "../views/Login.vue";
import AppChange from "../views/AppChange.vue";
import noMobile from "../views/noMobile/index.vue"

//解决重复点击一个导航
const originalPush = VueRouter.prototype.push;
VueRouter.prototype.push = function push(location) {
  return originalPush.call(this, location).catch((err) => err);
};

import detail from "./modules/detail";
import orderManagementDetail from "./modules/orderManagementDetail"; /* 工单管理详情路由 */
import productionPlanDetail from "./modules/productionPlanDetail"; /* 生产计划详情路由 */

Vue.use(VueRouter);
const routes = [
  {
    path: "/",
    redirect: "/Home",
  },
  {
    path: "/login",
    name: "login",
    component: Login,
  },
  {
    path: "/appChange",
    name: "appChange",
    component: AppChange,
  },
  {
    path: "/noMobile",
    meta: {
      title: "禁止访问",
    },
    component: noMobile,
  },
  {
    path: "",
    name: "Detail",
    component: Detail,
    hidden: false,
    children: [
      ...detail,
      ...productionPlanDetail,
      ...orderManagementDetail,
    ],
  },
];

const router = new VueRouter({
  //mode: 'history',
  mode: "hash",
  base: process.env.BASE_URL,
  routes,
  scrollBehavior(to, from, savedPosition) {
    if (savedPosition) {
      return savedPosition;
    } else {
      return {
        x: 0,
        y: 0,
      };
    }
  },
});

export default router;
